<template>
	<view>
		<u-navbar leftIconColor="#fff" title="成为合伙人" @rightClick="rightClick" :autoBack="true">
		</u-navbar>
		<form @reset="formReset" @submit="formSubmit" :reportSubmit="true" >
			<view class="integral" :style="{marginTop: top + 'px'}">
				<!-- <view class="banner" v-if="img != ''">
					<view class="swiper-container">
						<view class="swiper">
							<image class="img" :src="url + img"></image>
						</view>
					</view>
				</view> -->
				<view class="header-banner">
					<view class="item">
						<image src="/static/ymq_canyino2o/wlgl.png" mode=""></image>
						<text>物料支持</text>
					</view>
					<view class="item">
						<image src="/static/ymq_canyino2o/tdzc.png" mode=""></image>
						<text>团队支持</text>
					</view>
					<view class="item">
						<image src="/static/ymq_canyino2o/jszc.png" mode=""></image>
						<text>技术支持</text>
					</view>
					<view class="item">
						<image src="/static/ymq_canyino2o/sczc.png" mode=""></image>
						<text>市场支持</text>
					</view>
				</view>
				<view class="form-box">
					<view class="banner1">
						<view class="huanying">
							欢迎加入
							<text>{{ pt_name }}</text>
							，请填写申请信息。
						</view>
						<view class="bannerbox">
							<view class="">邀请人:</view>
							<input :disabled="true" placeholderStyle="color:#252424;"type="text" :value="yqr" />
						</view>
						<view class="bannerbox">
							<view class="">姓名:</view>
							<input name="name" placeholder="请填写真实姓名" placeholderStyle="color:#252424;" type="text" />
						</view>
						<view class="bannerbox">
							<view class="">手机号:</view>
							<input name="tel" placeholder="请填写手机号码" placeholderStyle="color:#252424;" type="number" />
						</view>
						<view class="read">
							<checkbox-group name="checkbox" shape="circle">
								<checkbox value="1" shape="circle"></checkbox>
							</checkbox-group>
							<!-- <u-checkbox-group>
								<u-checkbox v-model="checked" shape="circle"></u-checkbox>
							</u-checkbox-group> -->
							<view>
								我已阅读并同意
								<text @tap="lookck" class="readfont">《申请分销商协议》</text>
							</view>
						</view>
					</view>
					<view class="weui-btn-area">
						<button class="weui-btn" formType="submit">
							立即成为合伙人
						</button>
					</view>
				</view>
			</view>
		</form>

		<!-- parse <template is="xytemp" :data="fwxy:fwxy,xymc:xymc,xynr:xynr"></template> -->
		<block name="xytemp">
			<view class="zhezhao" v-if="!fwxy"></view>
			<view :class="'kcrzxy ' + (fwxy ? '' : 'active')">
				<view class="kcrzxyhd">{{ xymc }}</view>
				<scroll-view scrollY class="kcrzxybd" style="height: 600rpx">
					<rich-text :nodes="xynr"></rich-text>
				</scroll-view>
				<view @tap="queren" class="queren">确定</view>
			</view>
		</block>
	</view>
</template>

<script>
	import cardlist from '@/ymq_canyino2o/dist/cardlist/index'
	import gettel from '@/ymq_canyino2o/dist/gettel/index'
	var app = getApp()
	export default {
		components: {
			cardlist,
			gettel
		},
		data() {
			return {
				accountIndex: 0,
				fwxy: true,
				xymc: '申请分销商协议',
				xynr: '',
				url: '',
				img: '',
				fxset: '',
				yqr: '',
				pt_name: '',
				color: '',
				top: 0
			}
		},
		onLoad: function(t) {
			app.globalData.setNavigationBarColor(this)
			var that = this
			var a = uni.getStorageSync('users').id
			app.globalData.util.request({
				url: 'entry/wxapp/Url',
				cachetime: '0',
				success: function(t) {
					console.log(t)
					that.setData({
						url: t.data
					})
				}
			})
			app.globalData.util.request({
				url: 'entry/wxapp/CheckRetail',
				cachetime: '0',
				success: function(t) {
					console.log(t.data)
					that.setData({
						img: t.data.img2,
						xynr: t.data.fx_details,
						fxset: t.data
					})
				}
			})
			app.globalData.util.request({
				url: 'entry/wxapp/MySx',
				cachetime: '0',
				data: {
					user_id: a
				},
				success: function(t) {
					console.log(t.data)
					if (t.data) {
						that.setData({
							yqr: t.data.name
						})
					} else {
						that.setData({
							yqr: '总店'
						})
					}
				}
			})
			app.globalData.util.request({
				url: 'entry/wxapp/system',
				cachetime: '0',
				success: function(t) {
					console.log(t)
					that.setData({
						pt_name: t.data.url_name
					})
				}
			})
		},
		onReady: function() {},
		onShow: function() {
			this.top = uni.getSystemInfoSync().statusBarHeight + 44
		},
		onHide: function() {},
		onUnload: function() {},
		onPullDownRefresh: function() {},
		onReachBottom: function() {},
		methods: {
			rightClick() {
				uni.navigateBack(1)
			},
			lookck: function() {
				this.setData({
					fwxy: false
				})
			},

			queren: function() {
				this.setData({
					fwxy: true
				})
			},

			bindAccountChange: function(t) {
				console.log('picker account 发生选择改变，携带值为', t.detail.value)
				this.setData({
					accountIndex: t.detail.value
				})
			},

			tzweb: function(t) {
				console.log(t.currentTarget.dataset.index, this.lblist)
				var e = this.lblist[t.currentTarget.dataset.index]
				var a = t.currentTarget.dataset.sjtype
				console.log(e)
				if ('1' == e.state) {
					uni.redirectTo({
						url: e.src
					})
				}
				if ('2' == e.state) {
					uni.navigateTo({
						url: '../car/car?vr=' + e.id + '&sjtype=' + a,
						success: function(t) {},
						fail: function(t) {},
						complete: function(t) {}
					})
				}
				if ('3' == e.state) {
					uni.navigateToMiniProgram({
						appId: e.appid,
						success: function(t) {
							console.log(t)
						}
					})
				}
			},

			formSubmit: function(t) {
				console.log('form发生了submit事件，携带数据为：', t.detail)
				var e = t.detail.value.name
				var a = t.detail.value.tel
				var n = t.detail.value.checkbox.length
				var o = uni.getStorageSync('users').id
				var s = getApp().globalData.getOpenId
				var i = t.detail.formId
				console.log(o, s, i, e, a)
				var c = ''
				var l = true
				if ('' == e) {
					c = '请填写姓名！'
				} else {
					if ('' == a) {
						c = '请填写联系电话！'
					} else {
						if (11 != a.length) {
							c = '手机号错误！'
						} else {
							if (0 == n) {
								c = '阅读并同意《申请分销商协议》'
							} else {
								l = false
								uni.showLoading({
									title: '加载中...',
									mask: true
								})
								app.globalData.util.request({
									url: 'entry/wxapp/SaveRetail',
									cachetime: '0',
									data: {
										user_id: o,
										user_name: e,
										user_tel: a
									},
									success: function(t) {
										console.log(t)
										if ('1' == t.data) {
											uni.showToast({
												title: '提交成功'
											})
											var e = getCurrentPages()
											console.log(e)
											if (1 < e.length) {
												e[e.length - 2].reLoad()
											}
											setTimeout(function() {
												uni.navigateBack({})
											}, 1000)
										} else {
											uni.showToast({
												title: '请重试！',
												icon: 'loading'
											})
											uni.hideLoading()
										}
									}
								})
							}
						}
					}
				}
				if (1 == l) {
					uni.showModal({
						title: '提示',
						content: c
					})
				}
			},

			formReset() {
				console.log('占位：函数 formReset 未声明')
			}
		}
	}
</script>
<style>
	@import './jrhhr.css';
</style>
<style lang="scss" scoped>
	::v-deep .u-status-bar,
	::v-deep .u-navbar__content {
		background-color: #4B7BFB !important;
		.u-navbar__content__title {
			color: #fff !important;
		}
	}
	
</style>